Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
@vendia/serverless-express
Advanced tools
This library enables you to utilize AWS Lambda and Amazon API Gateway to respond to web and API requests using your existing Node.js application framework.
@vendia/serverless-express is an npm package that allows you to run an Express.js application on AWS Lambda and Amazon API Gateway. It simplifies the process of deploying Express.js applications in a serverless environment, providing a seamless integration with AWS services.
Basic Setup
This code demonstrates the basic setup of an Express.js application using @vendia/serverless-express. It creates a simple Express app with a single route and exports a Lambda handler.
const serverlessExpress = require('@vendia/serverless-express');
const app = require('express')();
app.get('/hello', (req, res) => {
res.send('Hello, world!');
});
exports.handler = serverlessExpress({ app });
Custom Lambda Handler
This code shows how to create a custom Lambda handler using @vendia/serverless-express. It allows more control over the Lambda function's behavior by manually creating the server and proxying the event and context.
const serverlessExpress = require('@vendia/serverless-express');
const app = require('express')();
app.get('/hello', (req, res) => {
res.send('Hello, world!');
});
const server = serverlessExpress.createServer(app);
exports.handler = (event, context) => {
return serverlessExpress.proxy(server, event, context);
};
Middleware Integration
This example demonstrates how to integrate middleware into an Express.js application using @vendia/serverless-express. It includes JSON parsing and a custom logging middleware.
const serverlessExpress = require('@vendia/serverless-express');
const express = require('express');
const app = express();
app.use(express.json());
app.use((req, res, next) => {
console.log('Request received:', req.method, req.path);
next();
});
app.get('/hello', (req, res) => {
res.send('Hello, world!');
});
exports.handler = serverlessExpress({ app });
aws-serverless-express is another package that allows you to run Express.js applications on AWS Lambda and Amazon API Gateway. It provides similar functionality to @vendia/serverless-express but is less actively maintained. It also requires more boilerplate code for setup compared to @vendia/serverless-express.
serverless-http is a versatile package that supports multiple web frameworks, including Express.js, Koa, and Hapi, for deployment on AWS Lambda. It offers a more generic solution compared to @vendia/serverless-express, which is specifically tailored for Express.js applications.
lambda-api is a lightweight framework designed specifically for building APIs on AWS Lambda. While it is not based on Express.js, it offers a similar routing and middleware system. It is a good alternative if you are looking for a more Lambda-native solution without the overhead of Express.js.
On 11/30, the AWS Serverless Express library is moving to Vendia and will be rebranded to @vendia/serverless-express
. Similarly, the aws-serverless-express
NPM package will be deprecated in favor of @vendia/serverless-express.
Brett, the original creator of the Serverless Express library, will continue maintaining the repository and give it the attention and care it deserves. At the same time, we will be looking for additional contributors to participate in the development and stewardship of the Serverless Express library. AWS and the SAM team will remain involved in an administrative role alongside Vendia, Brett, and the new maintainers that will join the project.
We believe this is the best course of action to ensure that customers using this library get the best possible support in the future. To learn more about this move or become a maintainer of the new Serverless Express library, reach out to us through a GitHub issue on this repository.
Best, The AWS Serverless team, Brett & the Vendia team
Run serverless applications and REST APIs using your existing Node.js application framework, on top of AWS Lambda and Amazon API Gateway. The sample provided allows you to easily build serverless web applications/services and RESTful APIs using the Express framework.
npm install @vendia/serverless-express
// lambda.js
'use strict'
const serverlessExpress = require('@vendia/serverless-express')
const app = require('./app')
const server = serverlessExpress.createServer(app)
exports.handler = (event, context) => { serverlessExpress.proxy(server, event, context) }
Package and create your Lambda function, then configure a simple proxy API using Amazon API Gateway and integrate it with your Lambda function.
Want to get up and running quickly? Check out our basic starter example which includes:
This package includes middleware to easily get the event object Lambda receives from API Gateway
const serverlessExpressMiddleware = require('@vendia/serverless-express/middleware')
app.use(serverlessExpressMiddleware.eventContext())
app.get('/', (req, res) => {
res.json(req.apiGateway.event)
})
FAQs
This library enables you to utilize AWS Lambda and Amazon API Gateway to respond to web and API requests using your existing Node.js application framework.
The npm package @vendia/serverless-express receives a total of 261,013 weekly downloads. As such, @vendia/serverless-express popularity was classified as popular.
We found that @vendia/serverless-express demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.